package com.shortUrl.starter.util;

import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.mysqlclient.MySQLPool;
import io.vertx.mysqlclient.impl.MySQLPoolOptions;
import io.vertx.sqlclient.PoolOptions;
import io.vertx.sqlclient.SqlClient;

public class MysqlUtils {
    private static String url;
    private static PoolOptions poolOptions;
    static {

        try {
            JsonObject mysqlConfig = LoadConfigUtils.getConfig().getJsonObject("mysql");

            url = mysqlConfig.getString("mysqlUrl");

            poolOptions = new PoolOptions(mysqlConfig.getJsonObject("pool"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static SqlClient getMysqlClient(Vertx vertx) {
        return MySQLPool.client(vertx, url, new MySQLPoolOptions(poolOptions));
    }

}
